package com.jia.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

/**
 * 事件回调方式处理内聚性应用
 *
 * @Author: xiuyajia
 * @Date: 11/27/13 1:58 PM
 */
public class DrawView extends View {

    private float currentX = 40;
    private float currentY = 50;

    //定义创建画笔
    Paint paint = new Paint();

    public DrawView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(Color.RED);
        canvas.drawCircle(currentX, currentY, 15, paint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        this.currentX = event.getX();
        this.currentY = event.getY();

        //通知组件充绘
        this.invalidate();

        return true;
    }
}
